NanoPi / Copy to clipboard button for Seed Map [chunkbase]

// ==UserScript==
// @name         Copy to clipboard button for Seed Map [chunkbase]
// @namespace    https://openuserjs.org/users/NanoPi
// @version      0.2.1
// @license      MIT
// @description  One-click copy coordinates from chunkbase in text formats recognized by minimap mods.
// @author       NanoPi
// @match        https://www.chunkbase.com/apps/seed-map
// @grant        none
// ==/UserScript==
(function () {
    'use strict';
    var dimensionsV = {
        overworld: "overworld",
        nether: "the_nether",
        end: "the_end"
    };
    var dimensionsX = {
        overworld: "overworld",
        nether: "the-nether",
        end: "the-end"
    };
    var dimensionsJ = {
        overworld: "0",
        nether: "-1",
        end: "1"
    };
    function mkbutton(text){
        var button = document.createElement('button');
        button.textContent = text;
        button.style = "font-size: unset;";
        button.title = "copy";
        return button;
    }
    var copyT = mkbutton("/tp");
    var tpcmd = "";
    var copyV = mkbutton("\u{1F4CD}V");
    var voxelmap = "";
    var copyX = mkbutton("\u{1F4CD}X");
    var xaerosminimap = "";
    var copyJ = mkbutton("\u{1F4CD}J");
    var journeymap = "";
    var copyA = mkbutton("\u{1F4CD}A");
    var allformats = "";

    function gettippy(e){
        console.log(e);
        var tippyboxes = document.getElementsByClassName("tippy-box");
        var tippycontent = document.getElementsByClassName("tippy-content");
        var dimselect = document.getElementById("biome-dimension-select");
        if (tippyboxes.length > 0 && tippycontent.length > 0) {
            var tippybox = tippyboxes[0];
            var text = tippycontent[0].innerText;
            var r, name, x, y, z, dim;
            r = text.match(/^(.+)\nX: ([-,0-9]+) Z: ([-,0-9]+)$/);
            if (r) {
                name=r[1]; x=r[2].replace(/,/g, ''); z=r[3].replace(/,/g, ''); dim=dimselect.value;
                voxelmap = `[name:${name.replace(/,/g,"\uFE50")}, x:${x}, z:${z}, dim:minecraft:${dimensionsV[dim]}]`;
                xaerosminimap = `xaero-waypoint:${name.replace(/:/g,"^col^")}:${name.substr(0,1)}:${x}:64:${z}:6:false:0:Internal-${dimensionsX[dim]}-waypoints`;
                tpcmd = `/tp @s ${x} ~ ${z}`;
                journeymap = `[name:${name.replace(/,/g,"").replace(/\"/g,"").replace(/\'/g,"")}, x:${x}, z:${z}, dim:${dimensionsJ[dim]}]`;
                allformats = `${voxelmap} ${journeymap} ${xaerosminimap}`;
                updatebutton();
            }
            r = text.match(/^(.+)\nX: ([-,0-9]+) Y: ([-,0-9]+) Z: ([-,0-9]+)$/);
            if (r) {
                name=r[1]; x=r[2].replace(/,/g, ''); y=r[3].replace(/,/g, ''); z=r[4].replace(/,/g, ''); dim=dimselect.value;
                voxelmap = `[name:${name.replace(/,/g,"\uFE50")}, x:${x}, y:${y}, z:${z}, dim:minecraft:${dimensionsV[dim]}]`;
                xaerosminimap = `xaero-waypoint:${name.replace(/:/g,"^col^")}:${name.substr(0,1)}:${x}:${y}:${z}:6:false:0:Internal-${dimensionsX[dim]}-waypoints`;
                tpcmd = `/tp @s ${x} ${y} ${z}`;
                journeymap = `[name:${name.replace(/,/g,"").replace(/\"/g,"").replace(/\'/g,"")}, x:${x}, y:${y}, z:${z}, dim:${dimensionsJ[dim]}]`;
                allformats = `${voxelmap} ${journeymap} ${xaerosminimap}`;
                updatebutton();
            }
        }
    }

    function updatebutton(){
        var tippyboxes = document.getElementsByClassName("tippy-box");
        var tippycontent = document.getElementsByClassName("tippy-content");
        if (tippyboxes.length > 0 && tippycontent.length > 0) {
            var tippybox = tippyboxes[0];
            if (!tippybox.dataset.hasOwnProperty("addedbutton")) {
                var lfc = tippybox.firstChild;
                tippybox.insertBefore(document.createTextNode("\u{1F4CB}"),lfc);
                tippybox.insertBefore(copyA,lfc);
                copyA.addEventListener('click',copytextA,true);
                tippybox.insertBefore(copyT,lfc);
                copyT.addEventListener('click',copytextT,true);
                tippybox.insertBefore(copyV,lfc);
                copyV.addEventListener('click',copytextV,true);
                tippybox.insertBefore(copyX,lfc);
                copyX.addEventListener('click',copytextX,true);
                tippybox.insertBefore(copyJ,lfc);
                copyJ.addEventListener('click',copytextJ,true);
                tippybox.dataset.addedbutton=true;
            }
            copyJ.title = journeymap;
            copyT.title = tpcmd;
            copyV.title = voxelmap;
            copyX.title = xaerosminimap;
            copyA.title = `VoxelMap: ${voxelmap}\nJourneyMap: ${journeymap}\nXaero's Minimap: ${xaerosminimap}`
        }
    }

    function copytextA(e){
        navigator.clipboard.writeText(allformats);
    }
    function copytextJ(e){
        navigator.clipboard.writeText(journeymap);
    }
    function copytextT(e){
        navigator.clipboard.writeText(tpcmd);
    }
    function copytextV(e){
        navigator.clipboard.writeText(voxelmap);
    }
    function copytextX(e){
        navigator.clipboard.writeText(xaerosminimap);
    }

    function attachlistener () {
        var app = document.getElementById("app");
        app.addEventListener('click', gettippy, true);
    }

    attachlistener();
}());